package com.gserver.game.rank.impl;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import com.gserver.game.character.Player;
import com.gserver.game.rank.IRank;
import com.gserver.game.rank.IRankManager;

public class RankManagerImpl implements IRankManager {

	/** 存放所有排行列表 */
	private Map<Integer, IRank> map = new HashMap<Integer, IRank>();

	public RankManagerImpl() {
		// 初始化等级排行
		 IRank rank = new GradeRank();
		 map.put(rank.getType(), rank);
	}

	/**
	 * 更新所有排行，带时间限制Object... params
	 */
	public void upAllRank(Object... pams) {
		for (IRank rank : map.values()) {
			rank.upRank(pams);
		}
	}

	/**
	 * 获取所有排行
	 * 
	 * @return
	 */
	public Collection<IRank> getRanks() {
		return map.values();
	}

	/**
	 * 获取指定排行
	 * 
	 * @param type
	 * @return
	 */
	public IRank get(int type) {
		return map.get(type);
	}

	/**
	 * 发送所有排行数据到客户端
	 * 
	 * @param player
	 */
	public void sendRankList(Player player, int type, short pageN) {
		IRank arrange = map.get(type);
		if (arrange == null) {
			return;
		}
		// MessagePlayer m = new MessagePlayer(MessageType.SC_ARRANGE_LIST);
		//
		// List<Object[]> list = arrange.getArranges();
		//
		// PageModel pm = new PageModel(list, 20);
		// List<Object[]> sublist = pm.getObjects(pageN);
		// m.setShort((short)arrange.getType());
		// m.setShort(pageN);
		// m.setShort((short)sublist.size());
		// for(Object[] a : sublist)
		// {
		// for(Object b : a){
		// m.setObject(b);
		// }
		// }
		// player.sendMessage(m);
	}

	/**
	 * 发送所有排行数据到客户端
	 * 
	 * @param player
	 */
	public void sendRankList(Player player, int type) {
		IRank arrange = map.get(type);
		if (arrange == null) {
			return;
		}
		// MessagePlayer m = new MessagePlayer(MessageType.SC_ARRANGE_LIST);
		//
		// List<Object[]> list = arrange.getArranges();
		// m.setShort((short)arrange.getType());
		// m.setShort((short)list.size());
		// for(Object[] a : list)
		// {
		// for(Object b : a){
		// m.setObject(b);
		// }
		// }
		// player.sendMessage(m);
	}

}
